package cn.jit.interceptor;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 记录访问路径
 * @author Cecurio
 *
 */
public class AccessInterceptor extends HandlerInterceptorAdapter {
	
	private static final Logger logger = Logger.getLogger(AccessInterceptor.class);
	
	@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri = request.getRequestURI();
        logger.info("访问的URI是==> " + uri);
        
        if (handler instanceof HandlerMethod) {
        	HandlerMethod handlerMethod = (HandlerMethod) handler;
            Method method = handlerMethod.getMethod();
            logger.info("方法所在类名==> " + method.getDeclaringClass().getName());
            logger.info("方法名==> " + method.getName());
		}
                
        // 只是记录日志，全都放行
        return true;
    }

}
